package com.wswy.wzcx.model;

import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;
import com.google.gson.annotations.SerializedName;

public class WZCity implements ICity, Parcelable {


  public static final WZCity DEFAULT = new WZCity("上海","shanghai","310100000000",3,"上海");


  @SerializedName("name")
  public String name;

  @SerializedName("nameCn")
  public String nameCn;

  @SerializedName("areaCode")
  public String areaCode;

  private transient int firstLetterId;
  private transient String firstLetter;

  @SerializedName("pid")
  public int pid;

  @SerializedName("pname")
  public String pname;

  @Override
  public int describeContents() {
    return 0;
  }

  @Override
  public void writeToParcel(Parcel dest, int flags) {
    dest.writeString(this.name);
    dest.writeString(this.nameCn);
    dest.writeString(this.areaCode);
    dest.writeInt(this.pid);
    dest.writeString(this.pname);
  }

  public WZCity(String name, String nameCn,String areaCode,int pid,String pname) {
    this.name = name;
    this.nameCn = nameCn;
    this.areaCode = areaCode;
    this.pid = pid;
    this.pname = pname;
  }


  protected WZCity(Parcel in) {
    this.name = in.readString();
    this.nameCn = in.readString();
    this.areaCode = in.readString();
    this.pid = in.readInt();
    this.pname = in.readString();
  }

  public static final Creator<WZCity> CREATOR = new Creator<WZCity>() {
    @Override
    public WZCity createFromParcel(Parcel source) {
      return new WZCity(source);
    }

    @Override
    public WZCity[] newArray(int size) {
      return new WZCity[size];
    }
  };

  @Override
  public String getCityName() {
    return name;
  }

  @Override
  public long getHeaderId() {
    initFirst();

    return firstLetterId;
  }

  @Override
  public String getNameLatter() {
    initFirst();
    return firstLetter;
  }


  private void initFirst(){

    if (firstLetter == null && !TextUtils.isEmpty(nameCn)){
      firstLetter = String.valueOf(nameCn.charAt(0)).toUpperCase();

      firstLetterId = firstLetter.charAt(0);

    }

  }

  @Override
  public String toString() {
    return "WZCity{" +
        "name='" + name + '\'' +
        ", nameCn='" + nameCn + '\'' +
        ", areaCode='" + areaCode + '\'' +
        ", pid=" + pid +
        '}';
  }
}
